package com.tdma.g12.provider;

import com.tdma.g12.sql.ConnectionStatusHelper;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;

public class ConnectionStatusProvider extends ContentProvider
{

	//Definicion del CONTENT_URI
	private static final String uri = "content://com.tdma.g12.ConnectionStatus";
	public static final Uri CONTENT_URI = Uri.parse(uri);
	public static final int HISTORIAL = 1;
	public static final int ULTIMO = 2;
	
	private ConnectionStatusHelper _dataBaseHelper;
	public ConnectionStatusProvider()
	{
		// TODO Auto-generated constructor stub
	}

	@Override
	public int delete(Uri arg0, String arg1, String[] arg2)
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getType(Uri arg0)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Uri insert(Uri arg0, ContentValues cv)
	{
		int estado =  cv.getAsInteger("estado");
		_dataBaseHelper.registrarEstado(estado);
		return null;
	}

	@Override
	public boolean onCreate()
	{
		_dataBaseHelper = new ConnectionStatusHelper(getContext());
		return _dataBaseHelper != null;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder)
	{
		if(Integer.valueOf(selection) == HISTORIAL){
			return _dataBaseHelper.getHistorial();
		}
		else {
			return _dataBaseHelper.getLast();
		}
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs)
	{
		// TODO Auto-generated method stub
		return 0;
	}

}
